User Guide > Getting Started > Tutorial: Create Your First Project |
In this step-by-step tutorial we’ll build a complete application to recognize text in an image and output all the individual words and their locations to the terminal.
Before running this tutorial a license for OCRXpress for Node.js should already be installed.
If you have run the setup script in the install folder then you should already have an evaluation license. If not, then see Registering Evaluation Licenses to install a license. |
For this tutorial, you can use your favorite text editor (vim, gedit, emacs, etc.).
Copy Code | |
---|---|
var ocrx = require('ocr'); |
Copy Code | |
---|---|
console.log('\n....................... Begin Tutorial .......................\n'); |
Copy Code | |
---|---|
var params = { input: '/path/to/image/file.bmp', language: 'english' }; |
Copy Code | |
---|---|
function afterOCR (err, doc) { if (err) { console.log('There was an error processing this image:'); console.log('\t' + err); return; } // Output a message letting the user know we were successful. console.log('Successfully finished recognizing the image'); // Create an array with just the words. var wordArray = doc.getWords().map(function(element) { var obj = {}; obj[element.text] = element.area; return obj; }); // Display the words. console.log('These are the words in your images:'); console.log(wordArray); } |
Copy Code | |
---|---|
// Perform recognition. ocrx.recognize(params, afterOCR); console.log('The words in your image are automatically being detected'); |
Copy Code | |
---|---|
$ node ocrDemo.js |